package com.study.创造型模式.单例模式.饿汉式1;

public class SingletonTest01 {

    public static void main(String[] args) {
        Singleton singleton = Singleton.getInstance();
        Singleton singleton2 = Singleton.getInstance();
        System.out.println(singleton==singleton2);
        System.out.println(singleton.hashCode());
        System.out.println(singleton2.hashCode());
    }
}


//饿汉式  静态变量

class Singleton{
    //1、构造器私有化 ,外部不能new
    private Singleton(){}

    //2、在本类内部创建一个对象实例
   private static final Singleton instance = new Singleton();

    //3、提供一个公有的静态方法，返回实例对象
    public static Singleton getInstance(){
        return instance;
    }

}